package com.ywger.integration.resttemplate.inteceptor;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;

import java.io.IOException;

/**
 * @author chenmeng
 * @date 2021-07-17 19:17
 * @desc
 */
public class RestHeaderInterceptor  implements ClientHttpRequestInterceptor {

    public static String REFER="Referer";
    public static String REFER_VALUE="http://zccp.safe.regulation";

    @Override
    public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
        HttpHeaders headers = request.getHeaders();
        headers.add(REFER,REFER_VALUE);
        ClientHttpResponse response = execution.execute(request, body);
        return response;
    }
}
